package com.fauks.study.msweb.controller;

import com.fauks.study.msweb.entities.User;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;

@Controller
public class UserController {
    @RequestMapping("/userAdd")
    public String addUserView(User user) {
        return "users";
    }

    @RequestMapping(value = "/userAdd", method = RequestMethod.POST)
    public String addUser(@Valid User user, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return "users";
        } else {
            System.out.println(user);
            return "ok";
        }
    }
}
